package utilities
{
	import org.flixel.*;
	
	/**
	 * ...
	 * @author JAC
	 */
	public class HeatMap extends FlxObject
	{
		private var _map:Array;
		private var _lastTile:FlxPoint;
		
		public function HeatMap()
		{
			_map = new Array();
			_lastTile = null;
			
			for (var i:uint = 0; i < Maze.widthInTiles * Maze.heightInTiles; i++)
			{
				_map.push(0);
			}
		}
		
		override public function destroy():void
		{
			_map = null;
			_lastTile = null;
			
			super.destroy();
		}
		
		override public function update():void
		{	
			if (_lastTile == null)
			{
				_lastTile = Maze.getTileByPoint(Player.midpoint);
				_map[index(_lastTile)]++;
			}
			
			var currentTile:FlxPoint = Maze.getTileByPoint(Player.midpoint);
			
			if (currentTile.x != _lastTile.x || currentTile.y != _lastTile.y)
			{
				_lastTile = currentTile;
				_map[index(currentTile)]++;
			}
		}
		
		public function get data():Array
		{
			return _map;
		}
		
		public function clear():void
		{
			for (var i:uint = 0; i < Maze.widthInTiles * Maze.heightInTiles; i++)
			{
				_map[i] = 0;
			}
			
			_lastTile = null;
		}
		
		private function index(tile:FlxPoint):uint
		{
			return tile.y * Maze.widthInTiles + tile.x;
		}
	}
}